<?php
session_start();
date_default_timezone_set('America/Los_Angeles');
//include and parse config file
require_once 'config.php';

$library = array('functions','anchor');
array_push($library,$include);
foreach( $library as $lib ) {
	if(file_exists(ROOT .  BRANCH . "/library/$lib.php")) {
		require_once(ROOT . BRANCH . "/library/$lib.php");
	}
}

// setting includes from application library and classes
if($handle = opendir(ROOT . BRANCH . '/classes')) {
	while(false !== ($file = readdir($handle))) {
		if($file != "." && $file != ".." && $file != '.svn') {
			include_once(ROOT . BRANCH . "/classes/$file");
		}
	}
	closedir($handle);
}

//GET Params from the URL currently called
$params = getParams($_SERVER['QUERY_STRING']); //GET params in the query

//check if user is logged in, and do redirection accordingly, if needed
//Access Levels: 0 - No Login only. 1 - Login only; 2: No Website access. 3: All access.
if(!isset($access_level) || $access_level > 3) {
	$access_level = 1;
}
if($access_level == 0) {
	if(isLoggedIn()) {
		$instructor = new Instructor($_SESSION['logged_in']);
		redirect('home.php');
	}
} elseif($access_level == 1) {
	if(!isLoggedIn()) {
		$_SESSION['m'] = '3';
		redirect('index.php');
	} else {
		$instructor = new Instructor($_SESSION['logged_in']);
	}
} elseif($access_level == 2) {
	$_SESSION['m'] = '5';
	redirect('index.php');
} elseif($access_level == 3) {
	if(isLoggedIn()) {
		$instructor = new Instructor($_SESSION['logged_in']);
	}
}

// linking stylesheets and javascript files
$style_sheet = array('default');
if(is_array($style)) {
	$style_sheet = array_merge($style_sheet,$style);
} else {
	array_push($style_sheet,$style);
}
$java_script = array('mootools','mootools-more','default');
if(is_array($script)) {
	$java_script = array_merge($java_script,$script);
} else {
	array_push($java_script,$script);
}

$hosturl = 'http://'.HOST;
?>